﻿using Abp.Application.Services;
using Abp.Application.Services.Dto;
using Abp.AspNetCore.Mvc.Authorization;
using AbpZeroTemplate.Authorization;
using AbpZeroTemplate.Localization;
using AbpZeroTemplate.Localization.Dto;
using AbpZeroTemplate.Web.Controllers;
using AbpZeroTemplate.Web.Swagger;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;

namespace AbpZeroTemplate.Api.Admin.Controllers
{
    /// <summary>语言管理
    /// </summary>
    [Area("Admin")]
    [Route("Admin/Language/[action]")]
    [ApiName("Admin")]
    [RemoteService]
    [AbpMvcAuthorize(AppPermissions.Pages_Administration_Languages)]
    public class LanguageController : AbpZeroTemplateControllerBase
    {
        private readonly ILanguageAppService _languageAppService;
        /// <summary>Ctor
        /// </summary>
        public LanguageController(ILanguageAppService languageAppService)
        {
            _languageAppService = languageAppService;
        }

        /// <summary>获取语言
        /// </summary>
        [HttpGet]
        public async Task<GetLanguagesOutput> GetLanguages()
        {
            return await _languageAppService.GetLanguages();
        }

        /// <summary>获取编辑的语言
        /// </summary>
        [HttpGet]
        [AbpMvcAuthorize(AppPermissions.Pages_Administration_Languages_Create, AppPermissions.Pages_Administration_Languages_Edit)]
        public async Task<GetLanguageForEditOutput> GetLanguageForEdit(NullableIdDto input)
        {
            return await _languageAppService.GetLanguageForEdit(input);
        }

        /// <summary>创建或者修改语言
        /// </summary>
        [HttpPost]
        public async Task CreateOrUpdateLanguage([FromBody]CreateOrUpdateLanguageInput input)
        {
            await _languageAppService.CreateOrUpdateLanguage(input);
        }

        /// <summary>删除语言
        /// </summary>
        [HttpDelete]
        public async Task DeleteLanguage([FromBody]EntityDto input)
        {
            await _languageAppService.DeleteLanguage(input);
        }

        /// <summary>设置默认语言
        /// </summary>
        [HttpPost]
        public async Task SetDefaultLanguage([FromBody]SetDefaultLanguageInput input)
        {
            await _languageAppService.SetDefaultLanguage(input);
        }

        /// <summary>获取多语言中的内容
        /// </summary>
        [HttpGet]
        [AbpMvcAuthorize(AppPermissions.Pages_Administration_Languages_ChangeTexts)]
        public async Task<PagedResultDto<LanguageTextListDto>> GetLanguageTexts(GetLanguageTextsInput input)
        {
            return await _languageAppService.GetLanguageTexts(input);
        }

        /// <summary>修改多语言内容
        /// </summary>
        [HttpPut]
        public async Task UpdateLanguageText([FromBody]UpdateLanguageTextInput input)
        {
            await _languageAppService.UpdateLanguageText(input);
        }
    }
}
